package com.itqf.service.impl;

import com.itqf.dao.ProductDao;
import com.itqf.dao.impl.ProductDaoImpl;
import com.itqf.entity.PageBean;
import com.itqf.entity.Product;
import com.itqf.service.ProductService;

import java.lang.reflect.InvocationTargetException;
import java.sql.SQLException;
import java.util.List;

public class ProductServiceImpl implements ProductService {

    //初始化dao层对象
    private ProductDao productDao = new ProductDaoImpl();

    @Override
    public PageBean<Product> findPage(String tid, int page, int pageSize) throws SQLException {

        long count = productDao.selectCountByTid(tid);//查询总条数

        List<Product> list = productDao.selectProductByPage(page,pageSize,tid);//查询当前页对应的商品

        //limit(currentPage-1)*pageSize,pageSize;

        return new PageBean<Product>(list,page,pageSize,count);
    }



    @Override
    public Product findProductByPid(String pid) throws SQLException {

        //调用dao层
        Product product = productDao.selectProductByPid(pid);

        return product;
    }

    @Override
    public List<Product> selectAll() throws IllegalAccessException, SQLException, InvocationTargetException {

        List<Product> productList = productDao.selectAll();
        System.out.println("商品模块业务层获取的productList:"+productList);
        return productList;
    }

    @Override
    public void addProduct(Product product) throws SQLException {
        productDao.addProduct(product);
    }
}
